﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
using DTOMall;

namespace MallProject.Admin.Usercontrol
{
    public partial class FormLogin : System.Web.UI.UserControl
    {
        String us = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            us = (string)Session["user_name"];
        }
        public void Login(string user, string pass)
    {
        DoLogin check = new DoLogin();
        DataTable dt = new DataTable();
        dt = check.GetUser(user, pass);
        if (dt.Rows.Count > 0)
        {
            string name = dt.Rows[0]["fullname"].ToString();
            int Role = Convert.ToInt32(dt.Rows[0]["group_id"]);
            string username = dt.Rows[0]["username"].ToString();
            if (Role == 1 || Role == 2 || Role ==3)
            {
                Session["Name"] = name;
                Session["Admin"] = (Int32)Role;
                Session.Timeout = 1000;
                Response.Redirect("User.aspx");
            }
        }
            else
                {
                    lblMess.Text = "Sai thông tin tài khoản !";
                }
            
        }




        public void btnLogin_Click(object sender, EventArgs e)
        {
            string un = txtUser.Text;
            string pass = txtPass.Text;
            Login(un, pass);
        }
    }
}